package com.jyb.qiyefuwu.view.fragment.usercenter;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.tabs.TabLayout;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.databinding.FragmentSaleorderTrademarklistBinding;
import com.jyb.qiyefuwu.uitls.CommPagerAdapter3;
import com.jyb.qiyefuwu.viewmodel.SaleTrademarkListViewModel;
import com.swgk.core.base.AppLazyFragment;

import org.jetbrains.annotations.NotNull;

public class PurchaseTrademarkListFragment extends AppLazyFragment {

    private FragmentSaleorderTrademarklistBinding mBinding;
    private SaleTrademarkListViewModel mViewModel;

    public static PurchaseTrademarkListFragment newInstance() {
        PurchaseTrademarkListFragment fragment = new PurchaseTrademarkListFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_saleorder_trademarklist, container, false);
        return mBinding.getRoot();
    }

    @Override
    protected void initView() {
        super.initView();
        mViewModel = new ViewModelProvider(this).get(SaleTrademarkListViewModel.class);
        mViewModel.fragmentList.add(SaleOrderListFragment.newInstance(1, 1, 1));
        mViewModel.fragmentList.add(SaleOrderListFragment.newInstance(2, 1, 1));
        mViewModel.fragmentList.add(SaleOrderListFragment.newInstance(4, 1, 1));
        mViewModel.fragmentList.add(SaleOrderListFragment.newInstance(5, 1, 1));
        mViewModel.fragmentList.add(SaleOrderListFragment.newInstance(3, 1, 1));
        CommPagerAdapter3 pagerAdapter = new CommPagerAdapter3(getChildFragmentManager(), mViewModel.fragmentList, mViewModel.title);
        mBinding.viewpager.setAdapter(pagerAdapter);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewpager);
        View linearLayout = LayoutInflater.from(getContext()).inflate(R.layout.item_tab_blod, null);
        TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
        mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        selectTextView.setText(mBinding.tabLayout.getTabAt(0).getText());
        mBinding.tabLayout.getTabAt(0).setCustomView(linearLayout);
        mBinding.tabLayout.getTabAt(0).select();

    }

    @Override
    protected void onLazyLoad() {

    }
}
